#!/bin/sh
. $HOME/.config/defaultprograms.txt
case "$1" in
 -default)
 echo $IMAGEVIEWER > $HOME/.config/tmp/viewer
 
 programchooser $IMAGEVIEWER applications-graphics 2DGraphics None > $HOME/.config/tmp/imageviewer
 cat $HOME/.config/defaultprograms.txt | grep -v IMAGEVIEWER > $HOME/.config/defaultprograms.new
 IMAGEVIEWER="`cat $HOME/.config/tmp/imageviewer`"
 [ "$IMAGEVIEWER" = "" ] && IMAGEVIEWER="cat $HOME/.config/tmp/viewer"
 echo IMAGEVIEWER=\"$IMAGEVIEWER\" >> $HOME/.config/defaultprograms.new
 mv -f $HOME/.config/defaultprograms.new $HOME/.config/defaultprograms.txt
 rm -f $HOME/.config/tmp/viewer
 rm -f $HOME/.config/tmp/imageviewer
 ;;
 *)
 exec $IMAGEVIEWER "$@"
 ;;
esac
